const { json } = require("express")
const express = require("express")
const Router = express.Router()
const fsp = require('fs/promises')
const path = require("path")


const dataUrl = path.join(__dirname, '../data/data.json')


Router.get("/user", function (req, res) {
    fsp.readFile(dataUrl, 'utf-8').then(data => {
        var user = JSON.parse(data).user
        if (user) {
            res.json(user)
        } else {
            res.send("/data/user not find data!")
        }
    })
})

Router.get("/list", function (req, res) {
    fsp.readFile(dataUrl, 'utf-8').then(data => {
        var list = JSON.parse(data).list
        if (list) {
            res.json(list)
        } else {
            res.send("/data/list not find data!")
        }
    })
})

Router.get("/pro", function (req, res) {
    fsp.readFile(dataUrl, 'utf-8').then(data => {
        var pro = JSON.parse(data).pro
        if (pro) {
            res.json(pro)
        } else {
            res.send("/data/pro not find data!")
        }
    })
})


module.exports = Router//暴露出去